import axios from 'axios'

import { Message } from "element-ui";
import 'element-ui/lib/theme-chalk/index.css'
import { removeToken } from "./token";
import router from "../router";

const request = axios.create({
	baseURL:'http://g1s.hfjava.cn:8080/api/',
})

//响应拦截器
request.interceptors.response.use(async (response)=>{
	// console.log(response)
	const code = response.data.code
	if(code !== "0"){
	  if (code === "1"){
      Message.error(response.data.msg)
    }
		if(code === "500"){
			Message.error(response.data.msg)
		}
		if(code === "401"){//返回错误
		  // 登录过期
			Message.warning(response.data.msg)
      removeToken()
      store.commit('REST_INFO')
			await router.push('/login')
		}
    return Promise.reject('请求失败')
  }else{
		return response
	}
})
export default request
